package org.beasy.binding.utils
{
	import mx.binding.utils.ChangeWatcher;
	import mx.styles.IStyleClient;
	
	/**
	 * Flex的绑定功能为我们的日常提供很多的方便
	 * 但是Flex只提供了属性的绑定类->BindingUtils;
	 * 如果要实现绑定控件的Style还要自己用ChangeWatcher去侦听事件
	 * 有了StyleBindingUtils这一切将变的简单
	 * StyleBindingUtils封装了ChangeWatcher进行了Style的绑定实现,
	 * 为您的开发提供了更多方便和快捷
	 * @author Marco
	 */
	public class StyleBindingUtils
	{
		public function StyleBindingUtils()
		{
		}
		
		public static function bindStyle(
			site:IStyleClient, prop:String,
			host:Object, chain:Object,
			commitOnly:Boolean = false):ChangeWatcher
		{
			var w:ChangeWatcher =
				ChangeWatcher.watch(host, chain, null, commitOnly);
			
			if(w != null )
			{
				var assign:Function = function(event:*):void
				{
					site.setStyle(prop, w.getValue());
				}
				w.setHandler( assign );
				assign(null);
			}
			
			return w;
		}
		
	}
}